home *** CD-ROM | disk | FTP | other *** search
/ Light ROM 1 / LIGHT-ROM 1 (Amiga Library Services)(1994).iso / ffdisks / d927.lha / Ftp / src / getpass.c < prev    next >
C/C++ Source or Header  |  1993-10-07  |  2KB  |  67 lines

  1. /*
  2.  * Copyright (c) 1988 The Regents of the University of California.
  3.  * All rights reserved.
  4.  *
  5.  * Redistribution and use in source and binary forms are permitted
  6.  * provided that the above copyright notice and this paragraph are
  7.  * duplicated in all such forms and that any documentation,
  8.  * advertising materials, and other materials related to such
  9.  * distribution and use acknowledge that the software was developed
  10.  * by the University of California, Berkeley.  The name of the
  11.  * University may not be used to endorse or promote products derived
  12.  * from this software without specific prior written permission.
  13.  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
  14.  * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
  15.  * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  16.  */
  17.  
  18. #if defined(LIBC_SCCS) && !defined(lint)
  19. static char sccsid[] = "@(#)getpass.c    based on 5.3 (Berkeley) 9/22/88";
  20. #endif /* LIBC_SCCS and not lint */
  21.  
  22. #include <stdio.h>
  23. #include <fcntl.h>
  24. #ifdef __SASC
  25. #include <ios1.h>
  26. #endif
  27.  
  28. char *
  29. getpass(prompt)
  30.     char *prompt;
  31. {
  32.     register int ch;
  33.     register char *p;
  34.     FILE *fp, *outfp;
  35. #define    PASSWD_LEN    128
  36.     static char buf[PASSWD_LEN + 1];
  37.  
  38.     /*
  39.      * read and write to /dev/tty if possible; else read from
  40.      * stdin and write to stderr.
  41.      */
  42.     outfp = stdout;
  43.     fp = stdin;
  44.  
  45. #ifdef __SASC
  46.     SetMode(chkufb(fileno(fp))->ufbfh,1L);
  47. #else
  48.     SetMode(_devtab[fileno(fp)].fd,1L);
  49. #endif
  50.     fputs(prompt, outfp);
  51.     fflush(outfp);
  52.     for (p = buf; (ch = getc(fp)) != EOF && ch != '\r';)
  53.         if (p < buf + PASSWD_LEN)
  54.             *p++ = ch;
  55.     *p = '\0';
  56.     (void)write(fileno(outfp), "\n", 1);
  57.  
  58. #ifdef __SASC
  59.     SetMode(chkufb(fileno(fp))->ufbfh,0L);
  60. #else
  61.     SetMode(_devtab[fileno(fp)].fd,0L);
  62. #endif
  63.  
  64.     return(buf);
  65. }
  66.  
  67.